﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ObserverPattern.ObserverDemo
{
    public class Cat
    {
        public void Miao() {

        }

        public List<IObserver> observerList = new List<IObserver>();

        public void AddObserver(IObserver observer)
        {
            observerList.Add(observer);
        }

        public void RemoveObserver(IObserver observer)
        {
            observerList.Remove(observer);
        }
         

        public string MiaoObserver() {

            string value = this.GetType().FullName;

            foreach (var obs in observerList)
            {
                value += "|" + obs.Action();
            }

            return value; 
        }


        public event Func<string> CatMiaoEvent;

        private static string valueEvent = string.Empty;

        public string MiaoEvent()
        {

             valueEvent += this.GetType().FullName;

            if (this.CatMiaoEvent != null)
            {
                valueEvent += "|" + this.CatMiaoEvent.Invoke();
            }

            return valueEvent;
        }

    }
}
